Skip to content

Check constants in parameters#5256

Merged
ondrejmirtes merged 13 commits into2.2.xfrom
constant-func-call
Mar 20, 2026
Merged

Check constants in parameters#5256
ondrejmirtes merged 13 commits into2.2.xfrom
constant-func-call

Conversation

@ondrejmirtes
Copy link
Copy Markdown
Member

@ondrejmirtes ondrejmirtes commented Mar 20, 2026

I prototyped a new pretty useful feature in a couple of hours.

In the end I want this to be gated behind the bleeding edge, but for now it always checks, so we can see the impact on issue-bot and integration tests.

Can you please review this and bring it over the finish line @staabm and @VincentLanglet?

Closes phpstan/phpstan#12850

@phpstan-bot
Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@ondrejmirtes ondrejmirtes marked this pull request as ready for review March 20, 2026 13:55
@ondrejmirtes ondrejmirtes merged commit c1a266e into 2.2.x Mar 20, 2026
121 of 122 checks passed
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes deleted the constant-func-call branch March 20, 2026 13:55
Copy link
Copy Markdown
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool, I didn't have the time to fully look at it ; you finished it quickly

@ondrejmirtes
Copy link
Copy Markdown
Member Author

You can still go through it to see if you find something to change

// JSON
// ————————————————————————————————————————————

'json_encode' => [
Copy link
Copy Markdown
Contributor

@staabm staabm Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how was this map generated? is it AI based? is it generated on other metadata (e.g. php8stubs or similar)?

is this something which can/could be typed via phpdoc instead (e.g. in stub files)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s Claude looking at PHP documentation and some relevant metadata in phpstorm-stubs describing this. The parameter names are proper from php-8-stubs, that’s why it’s behind “named arguments” support in PhpVersions.

Right now it’s only for built-in functions/methods/constants. If we find a use case for PHPDocs we can add it.

namespace ConstantParameterCheckCallUserFunc;

// call_user_func with correct constant
call_user_func('json_encode', [], JSON_PRETTY_PRINT);
Copy link
Copy Markdown
Contributor

@staabm staabm Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this, made me think that we could also support splat operator invocations:

https://phpstan.org/r/ed2c6e70-fef6-4fc1-93c9-3a3608223d9b

https://3v4l.org/8otIb

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is purely AST based.

@staabm
Copy link
Copy Markdown
Contributor

staabm commented Mar 21, 2026

it seems starting with this PR on 2.2.x a test started failling: https://github.com/phpstan/phpstan-src/actions/runs/23346042957/job/67911556548

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flock LOCK_SH, LOCK_EX, LOCK_UN options are exclusive

4 participants